import sys
import traceback

class DynamicModule(object):
	""" dynamic module object """
	pass

class CompileResult(object):
	""" stores the result of a compilation """
	module    = None
	success   = False
	message   = ''	
	def __init__(self, module=None, success=False, message=''):
		self.module  = module
		self.success = success
		self.message   = message

def compile_module(source):
	try:
		module = {}	
		bytecode = compile(source, '<string>', 'exec')
		exec bytecode in module
		ret = DynamicModule()
		for k, v in module.iteritems():
			setattr(ret, k, v)
		return CompileResult( module = ret, success = True)
	except:
		exc_type, exc_value, exc_traceback = sys.exc_info()
		return CompileResult( module = None, success = False, message =  str(exc_value)  )